package com.zrrd.yunchmall.product.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.module.Configuration;

/**
 * @author Liangyaoyun
 */
@RestController
//方式二:自动刷新属性的值
@RefreshScope
@SuppressWarnings("all")
public class ConfigTestController {
    //方式一:通过硬编码的方式获得环境中的属性最新值
    @Autowired
    public ConfigurableApplicationContext context;

    @Value("${author.name}")
    public String authorName;

    @RequestMapping("/configTest1")
    public String getAuthorProperty1(){//方式一
        return context.getEnvironment().getProperty("author.name");
    }

    @RequestMapping("/configTest2")
    public String getAuthorProperty2(){//方式二
        return authorName;
    }

}
